package com.service.impl;

import com.mapper.GroupCommentMapper;
import com.mapper.GroupListMapper;
import com.mapper.ShopCommentMapper;
import com.pojo.GroupComment;
import com.pojo.GroupCommentExample;
import com.pojo.GroupList;
import com.pojoVO.CommentInfoVo;
import com.pojoVO.GroupCommentVO;
import com.service.CommentInfoVoService;
import com.service.GroupCommentVOService;
import com.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GroupCommentVOServiceImpl implements GroupCommentVOService {
    @Autowired
    private GroupCommentMapper groupCommentMapper;
    @Autowired
    private GroupListMapper groupListMapper;
    @Autowired
    private CommentInfoVoService commentInfoVoService;
    @Override
    public ServerResponse getCommentMsg(Integer userId) {
        List<GroupCommentVO> groupCommentVOList = new ArrayList<>();
        ServerResponse serverResponse = commentInfoVoService.getByUserId(userId);
        if(serverResponse.getStatus() == 1){
            List<CommentInfoVo> commentInfoVolist = (List<CommentInfoVo>)serverResponse.getData();
            Integer groupid ;
            GroupCommentVO groupCommentVO =new GroupCommentVO();
            for(CommentInfoVo commentInfoVo :commentInfoVolist){
                groupid = commentInfoVo.getGroupId();
                GroupList groupList = groupListMapper.selectByPrimaryKey(groupid);
                groupCommentVO.setGroupList(groupList);
                groupCommentVO.setCommentInfoVo(commentInfoVo);
                groupCommentVOList.add(groupCommentVO);
            }
            return ServerResponse.getDataSuccess(groupCommentVOList);
        }else {
            return ServerResponse.getDataFailed("没有数据");
        }

    }
}
